package com.qf.erpb.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.erpb.core.utils.JwtUtils;
import com.qf.erpb.product.entity.XgUser2;
import com.qf.erpb.product.param.User2Param;
import com.qf.erpb.product.service.XgUser2Service;
import com.qf.erpb.product.dao.XgUser2Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
* @author DELL
* @description 针对表【xg_user】的数据库操作Service实现
* @createDate 2023-12-18 20:54:37
*/
@Service
public class XgUser2ServiceImpl extends ServiceImpl<XgUser2Mapper, XgUser2>
    implements XgUser2Service {

    @Resource
    private XgUser2Mapper xgUserMapper;
    @Override
    public String login(User2Param userParam) {
        XgUser2 user = xgUserMapper.selectOne(new LambdaQueryWrapper<XgUser2>().eq(XgUser2::getUsername, userParam.getUsername()));
        if (user == null) {
            throw new RuntimeException("用户名输入错误!");
        }
        if (!user.getPassword().equals(userParam.getPassword())) {
            throw new RuntimeException("密码输入错误!");
        }

        // 生成 jwt
        Map<String, Object> map = new HashMap<>();
        map.put("id",user.getId());
        String jwt = JwtUtils.createJwt(map);
        return jwt;
    }
}




